#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;

const int MAXN = 1e5 + 10;

int fa[MAXN];

bool vis[MAXN];
int h[MAXN];

int n, m;
int u, v, k;
int num = 0;
int visnum = 0;
long long totalcost = 0;

struct edge2
{
    int from;
    int to;
    int weight;
} e[MAXN * 10];

edge2 ee[MAXN * 10];

bool cmp(const edge2 &A, const edge2 &B)
{
    if (h[A.to] > h[B.to])
        return true;
    else if (h[A.to] == h[B.to])
    {
        return A.weight < B.weight;
    }
    else
        return false;
}

void init()
{
    for (int i = 1; i <= n; i++)
    {
        fa[i] = i;
    }
}

int find(int x)
{
    if (x == fa[x])
        return x;
    fa[x] = find(fa[x]);
    return fa[x];
}

void merge(int x, int y)
{
    int tx = find(x);
    int ty = find(y);
    if (tx != ty)
    {
        fa[tx] = ty;
    }
}

void bfs() // bfs找到能够去到的点
{
    queue<int> q;
    q.push(1);
    vis[1] = true;
    while (!q.empty())
    {
        int u = q.front();
        q.pop();
        for (int i = 1; i <= m; i++)
        {
            if (e[i].from == u)
            {
                auto to = e[i].to;
                if (!vis[to] && h[u] >= h[to])
                {
                    vis[to] = true;
                    q.push(to);
                }
            }
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (vis[i])
            visnum++;
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> h[i];
    }
    for (int i = 1; i <= m; i++)
    {
        cin >> u >> v >> k;
        if(h[u]>=h[v]) e[i] = {u, v, k}; 
        else e[i] = {v, u,k};
    }
    bfs();
    int cnt = 1;
    for (int i = 1; i <= m; i++)
    {
        if (vis[e[i].from])
        {
            ee[cnt++] = e[i];
        }
    }

    init();
    sort(ee+1, ee+1+cnt, cmp);

    for (int i = 1; i < cnt; i++)
    {
        if (find(ee[i].to) != find(ee[i].from))
        {
            merge(ee[i].to, ee[i].from); //合并
            num++;
            totalcost += ee[i].weight;
        }
        if (num == cnt - 2)
        {
            cout << visnum << " " << totalcost << endl;
            system("pause");
            return 0;
        }
    }
    system("pause");
    return 0;
}